/*!
 * jQuery Cookie Plugin v1.3.1
 * https://github.com/carhartl/jquery-cookie
 *
 * Copyright 2013 Klaus Hartl
 * Released under the MIT license
 */
(function(factory) {
	if (typeof define === 'function' && define.amd) {
		// AMD. Register as anonymous module.
		define([ 'jquery' ], factory);
	} else {
		// Browser globals.
		factory(jQuery);
	}
}(function($) {

	var pluses = /\+/g;

	function decode(s) {
		if (config.raw) {
			return s;
		}
		try {
			// If we can't decode the cookie, ignore it, it's unusable.
			return decodeURIComponent(s.replace(pluses, ' '));
		} catch (e) {
		}
	}

	function decodeAndParse(s) {
		if (s.indexOf('"') === 0) {
			// This is a quoted cookie as according to RFC2068, unescape...
			s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
		}

		s = decode(s);

		try {
			// If we can't parse the cookie, ignore it, it's unusable.
			return config.json ? JSON.parse(s) : s;
		} catch (e) {
		}
	}

	var config = $.cookie = function(key, value, options) {

		// Write
		if (value !== undefined) {
			options = $.extend({}, config.defaults, options);

			if (typeof options.expires === 'number') {
				var days = options.expires, t = options.expires = new Date();
				t.setDate(t.getDate() + days);
			}

			value = config.json ? JSON.stringify(value) : String(value);

			return (document.cookie = [
					config.raw ? key : encodeURIComponent(key),
					'=',
					config.raw ? value : encodeURIComponent(value),
					options.expires ? '; expires='
							+ options.expires.toUTCString() : '', // use
																	// expires
																	// attribute,
																	// max-age
																	// is not
																	// supported
																	// by IE
					options.path ? '; path=' + options.path : '',
					options.domain ? '; domain=' + options.domain : '',
					options.secure ? '; secure' : '' ].join(''));
		}

		// Read

		var result = key ? undefined : {};

		// To prevent the for loop in the first place assign an empty array
		// in case there are no cookies at all. Also prevents odd result when
		// calling $.cookie().
		var cookies = document.cookie ? document.cookie.split('; ') : [];

		for ( var i = 0, l = cookies.length; i < l; i++) {
			var parts = cookies[i].split('=');
			var name = decode(parts.shift());
			var cookie = parts.join('=');

			if (key && key === name) {
				result = decodeAndParse(cookie);
				break;
			}

			// Prevent storing a cookie that we couldn't decode.
			if (!key && (cookie = decodeAndParse(cookie)) !== undefined) {
				result[name] = cookie;
			}
		}

		return result;
	};

	config.defaults = {};

	$.removeCookie = function(key, options) {
		if ($.cookie(key) !== undefined) {
			// Must not alter options, thus extending a fresh object...
			$.cookie(key, '', $.extend({}, options, {
				expires : -1
			}));
			return true;
		}
		return false;
	};

}));

;
$(function() {
	// temp js ---代表首页-----------------
	var $_alerts = $("#header").find(".alert");
	var $_new_icon = "<i class='icon icon-red-point'></i>";
	if ($("#J_mainnav").val() == "J_main_index"&& $.cookie('J_cookie_notes') == null) {
			$.cookie('J_cookie_notes', 'J_index_notes', {
				expires : 30,
				path : '/',
				domain : 'localhost'
			});
		$("#header .alert-box").show();
		var $_noteStr = $("<p id='J_temp_note_text'>新版红桃隆重上线！您的登录用户名和密码没有改变！我们为您提供更好的用户体验，还等什么？赶紧体验非一般的职场吧！</p>");
		var $_yellow = $_alerts.find(".a_yellow");
		$_yellow.hide();
		$_alerts.find(".alert-in").append($_noteStr);
		$_alerts.animate({
			top : 0,
			opactiy : 1,
			display : "block"
		}, "normal");
	}

	var orderFlag = $("div.a-group.J_class .current").data("url");
	var aClass = $(".category.current").data("url");
	var topClass = $("#topClass").data("url");
	var keyword = $("#keyword").val();
	
	var firstMasonry = null;
	if (topClass == "album") {
		firstMasonry = new Mod_masonry({
			containor : "#J_water_main",
			ceil : true,
			itemSelector : ".act_water",
			path : [ keyword + "/" + aClass + "/" + orderFlag + "/" ,"/"  ],
			dataType : topClass,
			maxArtId: $("#maxArtId").val(),
			pageOrNum : "num",
			state : {
				currNum : $("#firstStartNum").val()
			}
		});
	} else {
		firstMasonry = new Mod_masonry({
			containor : "#J_water_main",
			path : [ keyword + "/" + aClass + "/" + orderFlag + "/" ,"/" ],
			maxArtId: $("#maxArtId").val(),
			pageOrNum : "num",
			state : {
				currNum : $("#firstStartNum").val()
			}
		});
	}

	firstMasonry.setMasonry();
	firstMasonry.init();

	$("a.category").on(
			"click",
			function() {
				$("a.category").removeClass("current");
				if($(this).text()=="全部"){
					$("#J_ctg_drop_nav").attr("style","");
				}else{
					$("#J_ctg_drop_nav").attr("style","color: #D2221C;");
				}
				$(this).addClass("current");

				var orderFlag = $("div.a-group.J_class .current").data("url");
				var aClass = $(".category.current").data("url");
				var topClass = $("#topClass").data("url");
				var keyword = $("#keyword").val();

				$("#J_water_main .water").remove();
				
				if (topClass == 2 || topClass == 1) {
					$(window).off("smartscroll.waterwall");
					firstMasonry = new Mod_masonry({
						containor : "#J_water_main",
						ceil : true,
						itemSelector : ".act_water",
						path : [ keyword + "/" + aClass + "/" + orderFlag + "/" ,"/"  ],
						firstQuery : true,
						dataType : topClass,
						maxArtId: $("#maxArtId").val(),
						pageOrNum : "num",
						state : {
							currNum : 0
						}
					});
				} else {
					$(window).off("smartscroll.waterwall");
					firstMasonry = new Mod_masonry({
						containor : "#J_water_main",
						path : [ keyword + "/" + aClass + "/" + orderFlag + "/" ,"/"   ],
						firstQuery : true,
						maxArtId: $("#maxArtId").val(),
						pageOrNum : "num",
						state : {
							currNum : 0
						}
					});
				}
				
				firstMasonry.setMasonry();
				firstMasonry.init();
			});
	//判断ipad方向变化
	$(window).on('orientationchange',function(){
		firstMasonry.reloadItem();
	});
});